from openpyxl import Workbook
from openpyxl.chart import (
    RadarChart,
    Reference,
)

# 创建工作表
wb = Workbook()
ws = wb.active

# 准备数据
rows = [
    ['Month', "Bulbs", "Seeds", "Flowers", "Trees & shrubs"],
    ['Jan', 0, 2500, 500, 0, ],
    ['Feb', 0, 5500, 750, 1500],
    ['Mar', 0, 9000, 1500, 2500],
    ['Apr', 0, 6500, 2000, 4000],
    ['May', 0, 3500, 5500, 3500],
    ['Jun', 0, 0, 7500, 1500],
    ['Jul', 0, 0, 8500, 800],
    ['Aug', 1500, 0, 7000, 550],
    ['Sep', 5000, 0, 3500, 2500],
    ['Oct', 8500, 0, 2500, 6000],
    ['Nov', 3500, 0, 500, 5500],
    ['Dec', 500, 0, 100, 3000],
]

# 将数据追加到工作表
for row in rows:
    ws.append(row)

# 创建雷达图
chart = RadarChart()
# 类型
chart.type = "filled"
# 标签
labels = Reference(ws, min_col=1, min_row=2, max_row=13)
# 数据:第2-5列,第1-13行,是二维列表
data = Reference(ws, min_col=2, max_col=5, min_row=1, max_row=13)
# 追加数据
chart.add_data(data, titles_from_data=True)
# 设置分类
chart.set_categories(labels)
# 样式
chart.style = 26
# 标题
chart.title = "一张简单的雷达图"
# 删除y轴
chart.y_axis.delete = True
# 将图表追加到工作表
ws.add_chart(chart, "A17")
# 保存Excel
wb.save("radar.xlsx")
